from django.utils import simplejson as json


def item2Json(item):
    if not item:
        return {}
    itemJson = {
            'itemId' : item.id,
            'deployId': item.deployId,
            'name': item.name,
            'desc': item.desc,
            'categoryId': item.categoryId,
            'typeId': item.typeId,
            'attackType': item.attackType,
            'level': item.level,
            'qualityId': item.qualityId,
            'enchantTime': item.enchantTime,
            'bindType': item.bindType,
            'props': item.props,
            'propertySet': item.propertySet,
            'requiredLevel': item.requiredLevel,
            'requiredCareerId': item.requiredCareerId,
            'requiredGenderId': item.requiredGenderId,
            'unique': item.unique,
            'maxStack': item.maxStack,
            'recyclingPrice': item.recyclingPrice,
            'canSell': item.canSell,
            'skillId': item.skillId,
            'itemres': item.itemres,
            
    }
    return itemJson

def item2StoreJson(item):
    if not item:
        return {}
    itemJson = {
            'id' : item.deployId,
            'name': p_bracket(item.name),
            'desc': p_bracket(item.desc),
            'categoryId': p_bracket(item.categoryId),
            'typeId': p_bracket(item.typeId),
            'attackType': p_bracket(item.attackType),
            'level': p_bracket(item.level),
            'qualityId': p_bracket(item.qualityId),
            'enchantTime': p_bracket(item.enchantTime),
            'bindType': p_bracket(item.bindType),
            'props': p_bracket(item.props),
            'propertySet': p_bracket(item.propertySet),
            'requiredLevel': p_bracket(item.requiredLevel),
            'requiredCareerId': p_bracket(item.requiredCareerId),
            'requiredGenderId': p_bracket(item.requiredGenderId),
            'unique': p_bracket(item.unique),
            'maxStack': p_bracket(item.maxStack),
            'recyclingPrice': p_bracket(item.recyclingPrice),
            'canSell': p_bracket(item.canSell),
            'skillId': p_bracket(item.skillId),
            'itemres': p_bracket(item.itemres),
                }
    return itemJson


def skill2Json(skill):
    if not skill:
        return {}
    skillJson = {
            'skillId' : skill.id,
            'deployId': skill.deployId,
            'name': skill.name,
            'desc': skill.desc,
            'category': skill.category,
            'targetType': skill.targetType,
            'damage': skill.damage,
            'triggerDamage': skill.triggerDamage,
            'status': skill.status,
            'triggerStatus': skill.triggerStatus,
            'trigger': skill.trigger,
            'property': skill.property,
            'changeFury': skill.changeFury,
            'sound': skill.sound,
            'skillres': skill.skillres,
            
    }
    return skillJson

def skill2StoreJson(skill):
    if not skill:
        return {}
    skillJson = {
            'id' : skill.deployId,
            'name': p_bracket(skill.name),
            'desc': p_bracket(skill.desc),
            'category': p_bracket(skill.category),
            'targetType': p_bracket(skill.targetType),
            'damage': p_bracket(skill.damage),
            'triggerDamage': p_bracket(skill.triggerDamage),
            'status': p_bracket(skill.status),
            'triggerStatus': p_bracket(skill.triggerStatus),
            'trigger': p_bracket(skill.trigger),
            'property': p_bracket(skill.property),
            'changeFury': p_bracket(skill.changeFury),
            'sound': p_bracket(skill.sound),
            'skillres': p_bracket(skill.skillres),
                }
    return skillJson


def task2Json(task):
    if not task:
        return {}
    taskJson = {
            'taskId' : task.id,
            'deployId': task.deployId,
            'name': task.name,
            'desc': task.desc,
            'level': task.level,
            'catalog': task.catalog,
            'type': task.type,
            'dests': task.dests,
            'compaignId': task.compaignId,
            'postTaskId': task.postTaskId,
            'startTalk': task.startTalk,
            'endTalk': task.endTalk,
            'deduct': task.deduct,
            'reward': task.reward,
            
    }
    return taskJson

def task2StoreJson(task):
    if not task:
        return {}
    taskJson = {
            'id' : task.deployId,
            'name': p_bracket(task.name),
            'desc': p_bracket(task.desc),
            'level': p_bracket(task.level),
            'catalog': p_bracket(task.catalog),
            'type': p_bracket(task.type),
            'dests': p_bracket(task.dests),
            'compaignId': p_bracket(task.compaignId),
            'postTaskId': p_bracket(task.postTaskId),
            'startTalk': p_bracket(task.startTalk),
            'endTalk': p_bracket(task.endTalk),
            'deduct': p_bracket(task.deduct),
            'reward': p_bracket(task.reward),
                }
    return taskJson


def card2Json(card):
    if not card:
        return {}
    cardJson = {
            'cardId' : card.id,
            'deployId': card.deployId,
            'name': card.name,
            'desc': card.desc,
            'module': card.module,
            'catalog': card.catalog,
            'type': card.type,
            'quality': card.quality,
            'award': card.award,
            'condition': card.condition,
            'nextCardId': card.nextCardId,
            'cardres': card.cardres,
            
    }
    return cardJson

def card2StoreJson(card):
    if not card:
        return {}
    cardJson = {
            'id' : card.deployId,
            'name': p_bracket(card.name),
            'desc': p_bracket(card.desc),
            'module': p_bracket(card.module),
            'catalog': p_bracket(card.catalog),
            'type': p_bracket(card.type),
            'quality': p_bracket(card.quality),
            'award': p_bracket(card.award),
            'condition': p_bracket(card.condition),
            'nextCardId': p_bracket(card.nextCardId),
            'cardres': p_bracket(card.cardres),
                }
    return cardJson


def map2Json(map):
    if not map:
        return {}
    mapJson = {
            'mapId' : map.id,
            'deployId': map.deployId,
            'name': map.name,
            'campaignIds': map.campaignIds,
            'mapres': map.mapres,
            
    }
    return mapJson

def map2StoreJson(map):
    if not map:
        return {}
    mapJson = {
            'id' : map.deployId,
            'name': p_bracket(map.name),
            'campaignIds': p_bracket(map.campaignIds),
            'mapres': p_bracket(map.mapres),
                }
    return mapJson


def campaign2Json(campaign):
    if not campaign:
        return {}
    campaignJson = {
            'campaignId' : campaign.id,
            'deployId': campaign.deployId,
            'name': campaign.name,
            'desc': campaign.desc,
            'battlePointIds': campaign.battlePointIds,
            'status': campaign.status,
            'vip': campaign.vip,
            'mapId': campaign.mapId,
            'userLevel': campaign.userLevel,
            'coorX': campaign.coorX,
            'coorY': campaign.coorY,
            'music': campaign.music,
            'frontCompaignIds': campaign.frontCompaignIds,
            'afterCompaignIds': campaign.afterCompaignIds,
            
    }
    return campaignJson

def campaign2StoreJson(campaign):
    if not campaign:
        return {}
    campaignJson = {
            'id' : campaign.deployId,
            'name': p_bracket(campaign.name),
            'desc': p_bracket(campaign.desc),
            'battlePointIds': p_bracket(campaign.battlePointIds),
            'status': p_bracket(campaign.status),
            'vip': p_bracket(campaign.vip),
            'mapId': p_bracket(campaign.mapId),
            'userLevel': p_bracket(campaign.userLevel),
            'coorX': p_bracket(campaign.coorX),
            'coorY': p_bracket(campaign.coorY),
            'music': p_bracket(campaign.music),
            'frontCompaignIds': p_bracket(campaign.frontCompaignIds),
            'afterCompaignIds': p_bracket(campaign.afterCompaignIds),
                }
    return campaignJson


def battle_point2Json(battle_point):
    if not battle_point:
        return {}
    battle_pointJson = {
            'battle_pointId' : battle_point.id,
            'deployId': battle_point.deployId,
            'name': battle_point.name,
            'desc': battle_point.desc,
            'npcId': battle_point.npcId,
            'campaignId': battle_point.campaignId,
            'weatherIds': battle_point.weatherIds,
            'roundMax': battle_point.roundMax,
            'leaderDead': battle_point.leaderDead,
            'roundLimit': battle_point.roundLimit,
            'leader': battle_point.leader,
            'round': battle_point.round,
            'endCondition': battle_point.endCondition,
            'attackerMax': battle_point.attackerMax,
            'defenderMax': battle_point.defenderMax,
            'areaId': battle_point.areaId,
            'drops': battle_point.drops,
            'energyCost': battle_point.energyCost,
            'passCount': battle_point.passCount,
            'difficulty': battle_point.difficulty,
            'starMax': battle_point.starMax,
            'frontBattlePointIds': battle_point.frontBattlePointIds,
            'afterBattlePointIds': battle_point.afterBattlePointIds,
            
    }
    return battle_pointJson

def battle_point2StoreJson(battle_point):
    if not battle_point:
        return {}
    battle_pointJson = {
            'id' : battle_point.deployId,
            'name': p_bracket(battle_point.name),
            'desc': p_bracket(battle_point.desc),
            'npcId': p_bracket(battle_point.npcId),
            'campaignId': p_bracket(battle_point.campaignId),
            'weatherIds': p_bracket(battle_point.weatherIds),
            'roundMax': p_bracket(battle_point.roundMax),
            'leaderDead': p_bracket(battle_point.leaderDead),
            'roundLimit': p_bracket(battle_point.roundLimit),
            'leader': p_bracket(battle_point.leader),
            'round': p_bracket(battle_point.round),
            'endCondition': p_bracket(battle_point.endCondition),
            'attackerMax': p_bracket(battle_point.attackerMax),
            'defenderMax': p_bracket(battle_point.defenderMax),
            'areaId': p_bracket(battle_point.areaId),
            'drops': p_bracket(battle_point.drops),
            'energyCost': p_bracket(battle_point.energyCost),
            'passCount': p_bracket(battle_point.passCount),
            'difficulty': p_bracket(battle_point.difficulty),
            'starMax': p_bracket(battle_point.starMax),
            'frontBattlePointIds': p_bracket(battle_point.frontBattlePointIds),
            'afterBattlePointIds': p_bracket(battle_point.afterBattlePointIds),
                }
    return battle_pointJson


def level_prop2Json(level_prop):
    if not level_prop:
        return {}
    level_propJson = {
            'level_propId' : level_prop.id,
            'deployId': level_prop.deployId,
            'exp': level_prop.exp,
            'energyMax': level_prop.energyMax,
            'battleCount': level_prop.battleCount,
            'employeeCount': level_prop.employeeCount,
            'skillCount': level_prop.skillCount,
            'hp': level_prop.hp,
            'physicalatk': level_prop.physicalatk,
            'physicaldef': level_prop.physicaldef,
            'magicatk': level_prop.magicatk,
            'magicdef': level_prop.magicdef,
            'award': level_prop.award,
            'logos': level_prop.logos,
            
    }
    return level_propJson

def level_prop2StoreJson(level_prop):
    if not level_prop:
        return {}
    level_propJson = {
            'id' : level_prop.deployId,
            'exp': p_bracket(level_prop.exp),
            'energyMax': p_bracket(level_prop.energyMax),
            'battleCount': p_bracket(level_prop.battleCount),
            'employeeCount': p_bracket(level_prop.employeeCount),
            'skillCount': p_bracket(level_prop.skillCount),
            'hp': p_bracket(level_prop.hp),
            'physicalatk': p_bracket(level_prop.physicalatk),
            'physicaldef': p_bracket(level_prop.physicaldef),
            'magicatk': p_bracket(level_prop.magicatk),
            'magicdef': p_bracket(level_prop.magicdef),
            'award': p_bracket(level_prop.award),
            'logos': p_bracket(level_prop.logos),
                }
    return level_propJson


def npc2Json(npc):
    if not npc:
        return {}
    npcJson = {
            'npcId' : npc.id,
            'deployId': npc.deployId,
            'name': npc.name,
            'desc': npc.desc,
            'npcUnitIds': npc.npcUnitIds,
            'npcres': npc.npcres,
            
    }
    return npcJson

def npc2StoreJson(npc):
    if not npc:
        return {}
    npcJson = {
            'id' : npc.deployId,
            'name': p_bracket(npc.name),
            'desc': p_bracket(npc.desc),
            'npcUnitIds': p_bracket(npc.npcUnitIds),
            'npcres': p_bracket(npc.npcres),
                }
    return npcJson


def npc_unit2Json(npc_unit):
    if not npc_unit:
        return {}
    npc_unitJson = {
            'npc_unitId' : npc_unit.id,
            'deployId': npc_unit.deployId,
            'name': npc_unit.name,
            'desc': npc_unit.desc,
            'level': npc_unit.level,
            'career': npc_unit.career,
            'gender': npc_unit.gender,
            'npcId': npc_unit.npcId,
            'idx': npc_unit.idx,
            'pos': npc_unit.pos,
            'hp': npc_unit.hp,
            'attackId': npc_unit.attackId,
            'physicalatk': npc_unit.physicalatk,
            'physicaldef': npc_unit.physicaldef,
            'magicatk': npc_unit.magicatk,
            'magicdef': npc_unit.magicdef,
            'furyAttackRate': npc_unit.furyAttackRate,
            'hardAttackRate': npc_unit.hardAttackRate,
            'hurtIncValue': npc_unit.hurtIncValue,
            'hurtDecValue': npc_unit.hurtDecValue,
            'hurtIncPercent': npc_unit.hurtIncPercent,
            'hurtDecPercent': npc_unit.hurtDecPercent,
            'skills': npc_unit.skills,
            'equipment': npc_unit.equipment,
            'style': npc_unit.style,
            'npcunitres': npc_unit.npcunitres,
            
    }
    return npc_unitJson

def npc_unit2StoreJson(npc_unit):
    if not npc_unit:
        return {}
    npc_unitJson = {
            'id' : npc_unit.deployId,
            'name': p_bracket(npc_unit.name),
            'desc': p_bracket(npc_unit.desc),
            'level': p_bracket(npc_unit.level),
            'career': p_bracket(npc_unit.career),
            'gender': p_bracket(npc_unit.gender),
            'npcId': p_bracket(npc_unit.npcId),
            'idx': p_bracket(npc_unit.idx),
            'pos': p_bracket(npc_unit.pos),
            'hp': p_bracket(npc_unit.hp),
            'attackId': p_bracket(npc_unit.attackId),
            'physicalatk': p_bracket(npc_unit.physicalatk),
            'physicaldef': p_bracket(npc_unit.physicaldef),
            'magicatk': p_bracket(npc_unit.magicatk),
            'magicdef': p_bracket(npc_unit.magicdef),
            'furyAttackRate': p_bracket(npc_unit.furyAttackRate),
            'hardAttackRate': p_bracket(npc_unit.hardAttackRate),
            'hurtIncValue': p_bracket(npc_unit.hurtIncValue),
            'hurtDecValue': p_bracket(npc_unit.hurtDecValue),
            'hurtIncPercent': p_bracket(npc_unit.hurtIncPercent),
            'hurtDecPercent': p_bracket(npc_unit.hurtDecPercent),
            'skills': p_bracket(npc_unit.skills),
            'equipment': p_bracket(npc_unit.equipment),
            'style': p_bracket(npc_unit.style),
            'npcunitres': p_bracket(npc_unit.npcunitres),
                }
    return npc_unitJson


def shop_item2Json(shop_item):
    if not shop_item:
        return {}
    shop_itemJson = {
            'shop_itemId' : shop_item.id,
            'deployId': shop_item.deployId,
            'tabId': shop_item.tabId,
            'itemId': shop_item.itemId,
            'coinPrice': shop_item.coinPrice,
            'silverPrice': shop_item.silverPrice,
            'status': shop_item.status,
            'isDiscount': shop_item.isDiscount,
            'coinPirceDiscount': shop_item.coinPirceDiscount,
            'silverPriceDiscount': shop_item.silverPriceDiscount,
            'levelLimit': shop_item.levelLimit,
            'vipLevelLimit': shop_item.vipLevelLimit,
            'rank': shop_item.rank,
            'shop_itemres': shop_item.shop_itemres,
            
    }
    return shop_itemJson

def shop_item2StoreJson(shop_item):
    if not shop_item:
        return {}
    shop_itemJson = {
            'id' : shop_item.deployId,
            'tabId': p_bracket(shop_item.tabId),
            'itemId': p_bracket(shop_item.itemId),
            'coinPrice': p_bracket(shop_item.coinPrice),
            'silverPrice': p_bracket(shop_item.silverPrice),
            'status': p_bracket(shop_item.status),
            'isDiscount': p_bracket(shop_item.isDiscount),
            'coinPirceDiscount': p_bracket(shop_item.coinPirceDiscount),
            'silverPriceDiscount': p_bracket(shop_item.silverPriceDiscount),
            'levelLimit': p_bracket(shop_item.levelLimit),
            'vipLevelLimit': p_bracket(shop_item.vipLevelLimit),
            'rank': p_bracket(shop_item.rank),
            'shop_itemres': p_bracket(shop_item.shop_itemres),
                }
    return shop_itemJson


def tavern2Json(tavern):
    if not tavern:
        return {}
    tavernJson = {
            'tavernId' : tavern.id,
            'deployId': tavern.deployId,
            'level': tavern.level,
            'requiredLevel': tavern.requiredLevel,
            'moneyType': tavern.moneyType,
            'money': tavern.money,
            'npcRates': tavern.npcRates,
            'taskRates': tavern.taskRates,
            
    }
    return tavernJson

def tavern2StoreJson(tavern):
    if not tavern:
        return {}
    tavernJson = {
            'id' : tavern.deployId,
            'level': p_bracket(tavern.level),
            'requiredLevel': p_bracket(tavern.requiredLevel),
            'moneyType': p_bracket(tavern.moneyType),
            'money': p_bracket(tavern.money),
            'npcRates': p_bracket(tavern.npcRates),
            'taskRates': p_bracket(tavern.taskRates),
                }
    return tavernJson


def versus_battle_point2Json(versus_battle_point):
    if not versus_battle_point:
        return {}
    versus_battle_pointJson = {
            'versus_battle_pointId' : versus_battle_point.id,
            'deployId': versus_battle_point.deployId,
            'level': versus_battle_point.level,
            'battlePointId': versus_battle_point.battlePointId,
            
    }
    return versus_battle_pointJson

def versus_battle_point2StoreJson(versus_battle_point):
    if not versus_battle_point:
        return {}
    versus_battle_pointJson = {
            'id' : versus_battle_point.deployId,
            'level': p_bracket(versus_battle_point.level),
            'battlePointId': p_bracket(versus_battle_point.battlePointId),
                }
    return versus_battle_pointJson


def constants2Json(constants):
    if not constants:
        return {}
    constantsJson = {
            'constantsId' : constants.id,
            'deployId': constants.deployId,
            'energeBoostPeriod': constants.energeBoostPeriod,
            'energeBoostUnit': constants.energeBoostUnit,
            'practiceDuration1': constants.practiceDuration1,
            'practiceDuration2': constants.practiceDuration2,
            'practiceDuration3': constants.practiceDuration3,
            'practiceSpeedExtraExp': constants.practiceSpeedExtraExp,
            'practiceCostCoeff1': constants.practiceCostCoeff1,
            'practiceCostCoeff2': constants.practiceCostCoeff2,
            'practiceCostCoeff3': constants.practiceCostCoeff3,
            'practiceSpeedCost': constants.practiceSpeedCost,
            'practiceDirectlyFinishCost': constants.practiceDirectlyFinishCost,
            'practiceExpUnitCoeff1': constants.practiceExpUnitCoeff1,
            'practiceExpUnitCoeff2': constants.practiceExpUnitCoeff2,
            'practiceExpUnitCoeff3': constants.practiceExpUnitCoeff3,
            'practiceSpeedItemId': constants.practiceSpeedItemId,
            'versusItemId': constants.versusItemId,
            'versusLevelLimit': constants.versusLevelLimit,
            
    }
    return constantsJson

def constants2StoreJson(constants):
    if not constants:
        return {}
    constantsJson = {
            'id' : constants.deployId,
            'energeBoostPeriod': p_bracket(constants.energeBoostPeriod),
            'energeBoostUnit': p_bracket(constants.energeBoostUnit),
            'practiceDuration1': p_bracket(constants.practiceDuration1),
            'practiceDuration2': p_bracket(constants.practiceDuration2),
            'practiceDuration3': p_bracket(constants.practiceDuration3),
            'practiceSpeedExtraExp': p_bracket(constants.practiceSpeedExtraExp),
            'practiceCostCoeff1': p_bracket(constants.practiceCostCoeff1),
            'practiceCostCoeff2': p_bracket(constants.practiceCostCoeff2),
            'practiceCostCoeff3': p_bracket(constants.practiceCostCoeff3),
            'practiceSpeedCost': p_bracket(constants.practiceSpeedCost),
            'practiceDirectlyFinishCost': p_bracket(constants.practiceDirectlyFinishCost),
            'practiceExpUnitCoeff1': p_bracket(constants.practiceExpUnitCoeff1),
            'practiceExpUnitCoeff2': p_bracket(constants.practiceExpUnitCoeff2),
            'practiceExpUnitCoeff3': p_bracket(constants.practiceExpUnitCoeff3),
            'practiceSpeedItemId': p_bracket(constants.practiceSpeedItemId),
            'versusItemId': p_bracket(constants.versusItemId),
            'versusLevelLimit': p_bracket(constants.versusLevelLimit),
                }
    return constantsJson


def forge_item_data2Json(forge_item_data):
    if not forge_item_data:
        return {}
    forge_item_dataJson = {
            'forge_item_dataId' : forge_item_data.id,
            'deployId': forge_item_data.deployId,
            'count': forge_item_data.count,
            'min': forge_item_data.min,
            'max': forge_item_data.max,
            'gold': forge_item_data.gold,
            
    }
    return forge_item_dataJson

def forge_item_data2StoreJson(forge_item_data):
    if not forge_item_data:
        return {}
    forge_item_dataJson = {
            'id' : forge_item_data.deployId,
            'count': p_bracket(forge_item_data.count),
            'min': p_bracket(forge_item_data.min),
            'max': p_bracket(forge_item_data.max),
            'gold': p_bracket(forge_item_data.gold),
                }
    return forge_item_dataJson


def item_fragment2Json(item_fragment):
    if not item_fragment:
        return {}
    item_fragmentJson = {
            'item_fragmentId' : item_fragment.id,
            'deployId': item_fragment.deployId,
            'itemId': item_fragment.itemId,
            'type': item_fragment.type,
            'fragments': item_fragment.fragments,
            
    }
    return item_fragmentJson

def item_fragment2StoreJson(item_fragment):
    if not item_fragment:
        return {}
    item_fragmentJson = {
            'id' : item_fragment.deployId,
            'itemId': p_bracket(item_fragment.itemId),
            'type': p_bracket(item_fragment.type),
            'fragments': p_bracket(item_fragment.fragments),
                }
    return item_fragmentJson


def item_extra_prop2Json(item_extra_prop):
    if not item_extra_prop:
        return {}
    item_extra_propJson = {
            'item_extra_propId' : item_extra_prop.id,
            'deployId': item_extra_prop.deployId,
            'level': item_extra_prop.level,
            'property': item_extra_prop.property,
            'valueType': item_extra_prop.valueType,
            'min': item_extra_prop.min,
            'max': item_extra_prop.max,
            
    }
    return item_extra_propJson

def item_extra_prop2StoreJson(item_extra_prop):
    if not item_extra_prop:
        return {}
    item_extra_propJson = {
            'id' : item_extra_prop.deployId,
            'level': p_bracket(item_extra_prop.level),
            'property': p_bracket(item_extra_prop.property),
            'valueType': p_bracket(item_extra_prop.valueType),
            'min': p_bracket(item_extra_prop.min),
            'max': p_bracket(item_extra_prop.max),
                }
    return item_extra_propJson


def item_perfect_prop_data2Json(item_perfect_prop_data):
    if not item_perfect_prop_data:
        return {}
    item_perfect_prop_dataJson = {
            'item_perfect_prop_dataId' : item_perfect_prop_data.id,
            'deployId': item_perfect_prop_data.deployId,
            'itemQuality': item_perfect_prop_data.itemQuality,
            'type': item_perfect_prop_data.type,
            'prop': item_perfect_prop_data.prop,
            'min': item_perfect_prop_data.min,
            'max': item_perfect_prop_data.max,
            
    }
    return item_perfect_prop_dataJson

def item_perfect_prop_data2StoreJson(item_perfect_prop_data):
    if not item_perfect_prop_data:
        return {}
    item_perfect_prop_dataJson = {
            'id' : item_perfect_prop_data.deployId,
            'itemQuality': p_bracket(item_perfect_prop_data.itemQuality),
            'type': p_bracket(item_perfect_prop_data.type),
            'prop': p_bracket(item_perfect_prop_data.prop),
            'min': p_bracket(item_perfect_prop_data.min),
            'max': p_bracket(item_perfect_prop_data.max),
                }
    return item_perfect_prop_dataJson


def home2Json(home):
    if not home:
        return {}
    homeJson = {
            'homeId' : home.id,
            'deployId': home.deployId,
            'homeId': home.homeId,
            'cellId': home.cellId,
            'level': home.level,
            'cardId': home.cardId,
            'taskId': home.taskId,
            'homeres': home.homeres,
            
    }
    return homeJson

def home2StoreJson(home):
    if not home:
        return {}
    homeJson = {
            'id' : home.deployId,
            'homeId': p_bracket(home.homeId),
            'cellId': p_bracket(home.cellId),
            'level': p_bracket(home.level),
            'cardId': p_bracket(home.cardId),
            'taskId': p_bracket(home.taskId),
            'homeres': p_bracket(home.homeres),
                }
    return homeJson


def open_bag2Json(open_bag):
    if not open_bag:
        return {}
    open_bagJson = {
            'open_bagId' : open_bag.id,
            'deployId': open_bag.deployId,
            'bagCount': open_bag.bagCount,
            'gold': open_bag.gold,
            
    }
    return open_bagJson

def open_bag2StoreJson(open_bag):
    if not open_bag:
        return {}
    open_bagJson = {
            'id' : open_bag.deployId,
            'bagCount': p_bracket(open_bag.bagCount),
            'gold': p_bracket(open_bag.gold),
                }
    return open_bagJson


def silver_bag2Json(silver_bag):
    if not silver_bag:
        return {}
    silver_bagJson = {
            'silver_bagId' : silver_bag.id,
            'deployId': silver_bag.deployId,
            'itemId': silver_bag.itemId,
            'silvers': silver_bag.silvers,
            
    }
    return silver_bagJson

def silver_bag2StoreJson(silver_bag):
    if not silver_bag:
        return {}
    silver_bagJson = {
            'id' : silver_bag.deployId,
            'itemId': p_bracket(silver_bag.itemId),
            'silvers': p_bracket(silver_bag.silvers),
                }
    return silver_bagJson


def gift_bag2Json(gift_bag):
    if not gift_bag:
        return {}
    gift_bagJson = {
            'gift_bagId' : gift_bag.id,
            'deployId': gift_bag.deployId,
            'itemId': gift_bag.itemId,
            'reward': gift_bag.reward,
            
    }
    return gift_bagJson

def gift_bag2StoreJson(gift_bag):
    if not gift_bag:
        return {}
    gift_bagJson = {
            'id' : gift_bag.deployId,
            'itemId': p_bracket(gift_bag.itemId),
            'reward': p_bracket(gift_bag.reward),
                }
    return gift_bagJson


def treasure2Json(treasure):
    if not treasure:
        return {}
    treasureJson = {
            'treasureId' : treasure.id,
            'deployId': treasure.deployId,
            'itemId': treasure.itemId,
            'items': treasure.items,
            
    }
    return treasureJson

def treasure2StoreJson(treasure):
    if not treasure:
        return {}
    treasureJson = {
            'id' : treasure.deployId,
            'itemId': p_bracket(treasure.itemId),
            'items': p_bracket(treasure.items),
                }
    return treasureJson


def p_bracket(value):
    if isinstance(value,basestring):
        if value.startswith("{") and value.endswith("}") or value.startswith("[") and value.endswith("]"):
            return json.loads(value.replace("\'","\""))
    return value